package com.springboot2.shiro.comm.service;

import com.springboot2.shiro.comm.repository.JpaExtraRepository;

import java.util.List;
import java.util.Optional;

/**
 * JpaService
 *
 * @author Archx[archx@foxmail.com]
 * at 2018/7/13 21:01
 */
public interface JpaService<ID extends Number, T, R extends JpaExtraRepository<ID, T>> {

    R getRepository();

    default Optional<T> findOne(ID id) {
        return getRepository().findById(id);
    }

    default List<T> findAll() {
        return getRepository().findAll();
    }

    default T save(T entity) {
        return getRepository().save(entity);
    }

    default List<T> save(List<T> entities) {
        return getRepository().saveAll(entities);
    }

    default void delete(T entity) {
        getRepository().delete(entity);
    }

    default void delete(ID id) {
        getRepository().deleteById(id);
    }
}
